package org.sun.log_manager_study.modules.user.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.sun.log_manager_study.modules.user.entity.User;
import org.sun.log_manager_study.modules.user.repository.UserRepository;
import org.sun.log_manager_study.modules.utils.UserDataGenerator;


@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private UserDataGenerator generator;

    @GetMapping("/findAll")
    public List<User> findAll() {
        return userRepository.findAll();
    }

    @GetMapping("/insert")
    public void insert() {
        try {
            generator.generateAndInsertTenMillionUsersMultiThread();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
